<?php
class MHDEV_View_Helper_GetActivityPoints extends Zend_View_Helper_Abstract
{
    public function GetActivityPoints($uid)
    {
    	// vars
    	$content	= array();
    	
    	// helper
    	$translation = Zend_Registry::get('lang');
    	
    	// db
		$user 	= new User();
		$rank	= new Rank();
		
		// query
		$userQuery = $user->find($uid);
		
		// res
		if($userQuery->count() > 0)
		{
			$getUser 	= $userQuery->toArray();
			$points		= $getUser[0]['activity_points'];
		
			$queryRank	= $rank->fetchAll($points. ' BETWEEN `xp_begin` AND `xp_end`');
			
			if($queryRank->count() > 0)
			{
				$getRank = $queryRank->toArray();
				
				$xp_start	= $getRank[0]['xp_begin'];
					
				$queryNextRank = $rank->fetchAll('xp_begin=' . ($getRank[0]['xp_end']+1));
				if($queryNextRank->count() > 0 )
				{
					$getNextRank 	= $queryNextRank->toArray();
					$xp_end			= $getNextRank[0]['xp_begin'];
					$content['points_till_next_lvl'] = ($getNextRank[0]['xp_begin']-$points);
				}
				else
				{
					$content['points_till_next_lvl'] = '???';
				}
				$content['title']		= $getRank[0]['lang_key'] ? $translation->_($getRank[0]['lang_key']) : $getRank[0]['title'];
				$content['points']		= $points;
				$content['next_lvl']	= $getRank[0]['xp_end'];
			}
		}
		
		$percent			= round(100/$xp_end*$points);
		$content['percent'] = $percent == 0 ? 1 : $percent;
		
		return $content;
    }
}
?>